home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 8.3 KB | 307 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UDialogBehavior.cp
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UDIALOGBEHAVIOR__
- #include "UDialogBehavior.h"
- #endif
-
- // MacApp
-
- #if qContainer
- #ifndef __UCONTAINER__
- #include "UContainer.h"
- #endif
- #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- // #ifndef __UMACAPPGLOBALS__
- // #include "UMacAppGlobals.h"
- // #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- #if qContainer
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
- #endif
-
- //========================================================================================
- // CLASS TDialogBehavior
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TDialogBehavior, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TDialogBehavior::TDialogBehavior()
- {
- fModal = FALSE;
- fDefaultItem = kNoIdentifier;
- fCancelItem = kNoIdentifier;
- fDismisser = kNoIdentifier;
- fDismissed = TRUE;
- } // TDialogBehavior::TDialogBehavior
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TDialogBehavior::~TDialogBehavior()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::IDialogBehavior:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDialogBehavior::IDialogBehavior(Boolean isModal,
- IDType itsDefaultItem,
- IDType itsCancelItem)
- {
- this->IBehavior(kDialogBehavior);
-
- fModal = isModal;
- fDefaultItem = itsDefaultItem;
- fCancelItem = itsCancelItem;
- } // TDialogBehavior::IDialogBehavior
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::ReadFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TDialogBehavior::ReadFrom(TStream* aStream) // override
- {
- Inherited::ReadFrom(aStream);
-
- fModal = aStream->ReadBoolean();
- fDefaultItem = aStream->ReadIDType();
- fCancelItem = aStream->ReadIDType();
- } // TDialogBehavior::ReadFrom
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::WriteTo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TDialogBehavior::WriteTo(TStream* aStream) // override
- {
- Inherited::WriteTo(aStream);
-
- aStream->WriteBoolean(fModal);
- aStream->WriteIDType(fDefaultItem);
- aStream->WriteIDType(fCancelItem);
- } // TDialogBehavior::WriteTo
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::Dismiss:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TDialogBehavior::Dismiss(IDType dismisser, Boolean validate)
- {
- TView* owner = ( TView* )fOwner;
-
- if (owner)
- {
- if (validate)
- {
- if (owner->IsHierarchyValid())
- {
- fDismisser = dismisser;
- fDismissed = TRUE;
- }
- }
- else
- {
- fDismisser = dismisser;
- fDismissed = TRUE;
- }
-
- }
-
- } // TDialogBehavior::Dismiss
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TDialogBehavior::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event)// override
- {
- if (eventNumber == mDismiss /*dismiss*/)
- {
- this->Dismiss(source->fIdentifier,source->fIdentifier != fCancelItem);
- }
- else
- Inherited::DoEvent(eventNumber, source, event);
-
- } // TDialogBehavior::DoEvent
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::DoKeyEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TDialogBehavior::DoKeyEvent(TToolboxEvent* event)// override
- {
- // Maps the Enter and Return keys to the default item (view)
- // Maps the Escape key to the cancel item (view)
-
- TView* owner = (TView*)fOwner;
- Boolean wasHandled = FALSE;
-
- if (owner && owner->IsEnabled())
- {
- if (event->fText == chEscape && event->fKeyCode != kClearVirtualCode) // esc double for two different keys!
- {
- if (fCancelItem != kNoIdentifier)
- {
- wasHandled = TRUE;
- TView * cancelView = owner->FindSubView(fCancelItem);
- if (cancelView)
- {
- if (cancelView->IsEnabled())
- cancelView->HandleEvent(cancelView->GetEventNumber(), owner, NULL);
- }
- else
- owner->HandleEvent(mCancelKey, owner, NULL);
- }
- }
- else if(event->fText == chEnter || event->fText == chReturn)
- {
- if (fDefaultItem != kNoIdentifier)
- {
- wasHandled = TRUE;
- TView * defaultView = owner->FindSubView(fDefaultItem);
- if (defaultView)
- {
- if (defaultView->IsEnabled())
- defaultView->HandleEvent(defaultView->GetEventNumber(), owner, NULL);
- }
- else
- owner->HandleEvent(mDefaultKey, owner, NULL);
- }
- }
- }
-
- if (!wasHandled)
- Inherited::DoKeyEvent(event);
- } // TDialogBehavior::DoKeyEvent
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::DoCommandKeyEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TDialogBehavior::DoCommandKeyEvent(TToolboxEvent* event)// override
-
- {
- // Maps Command-Period to the cancel item (view)
- TView* owner = (TView*)fOwner;
-
- if (owner && owner->IsEnabled() && event->fText == '.' && fCancelItem != kNoIdentifier)
- {
- TView* cancelView = owner->FindSubView(fCancelItem);
- if (cancelView)
- {
- if (cancelView->IsEnabled())
- cancelView->HandleEvent(cancelView->GetEventNumber(), owner, NULL);
- }
- else
- owner->HandleEvent(mCancelKey, owner, NULL);
- }
- else
- Inherited::DoCommandKeyEvent(event);
- } // TDialogBehavior::DoCommandKeyEvent
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::PoseModally:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TDialogBehavior::PoseModally()
- {
- #if qContainer
- WindowPtr dialogWindow = NULL;
- if (gContainerLib)
- {
- TView* owner = (TView*) fOwner;
- if (owner)
- {
- TWindow* window = owner->GetWindow();
- if (window)
- dialogWindow = window->fWMgrWindow;
- }
- }
-
- CModalFocus dialogFocus(dialogWindow);
- if (dialogFocus.Request())
- {
- #endif
- fDismissed = FALSE;
- fDismisser = kNoIdentifier;
- MAVolatile(short, oldEventMask);
- oldEventMask = gDispatcher->GetMainEventMask();
- gDispatcher->SetMainEventMask(oldEventMask & ~highLevelEventMask);
-
- FailInfo fi;
- Try(fi)
- {
- while (!fDismissed)
- gDispatcher->PollEvent(kAllowApplicationToSleep);
-
- gDispatcher->SetMainEventMask(oldEventMask);
- fi.Success();
- }
- else // Recover
- {
- gDispatcher->SetMainEventMask(oldEventMask);
- fi.ReSignal();
- }
- #if qContainer
- }
- #endif
- } // TDialogBehavior::PoseModally
-
- //----------------------------------------------------------------------------------------
- // TDialogBehavior::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TDialogBehavior::GetStandardSignature() // override
- {
- return kStdDialogBehavior;
- } // TDialogBehavior::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // End of UDialogBehavior.cp
-
- #pragma segment Inline
-